function loadJs(file){
     var head = $('head').remove('#loadScript');
    $("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendTo(head);
}


		//重复检查
function checkSubmit() {
//alert(checkSubmitFlg);
 if (checkSubmitFlg == true) { 
  return false;  
   }  
   checkSubmitFlg = true; 
 	return true;  
}    


document.ondblclick = function docondblclick() { 
   // window.event.returnValue = false;  
}      
//document.onclick = function doconclick() { 
 //   if (checkSubmitFlg) {  
 //        window.event.returnValue = false;
 //  }             
 //} 



//-----------------------------------------------------------------------------

function trim(str){  //删除左右两端的空格
 return str.replace(/(^s*)|(s*$)/g, "");
}
function ltrim(str){  //删除左边的空格
 return str.replace(/(^s*)/g,"");
}
function rtrim(str){  //删除右边的空格
 return str.replace(/(s*$)/g,"");
}

//选择所有CHECKBOX
function checkall(form,checkbox_name){
	for (i = 0; i < form.elements.length; i++){
		if (form.elements[i].name == checkbox_name){
			if (form.elements[i].checked){
				form.elements[i].checked = false;				
			}else{
				form.elements[i].checked = true;
			}
		}
	} 
}

function getFormValeStr(){
	var form=document.forms[0];
	str="";
	for (i = 0; i < form.elements.length; i++){		
		if (form.elements[i].name != "undefined"){
		 str=str+"&"+form.elements[i].name+"="+form.elements[i].value+"";
		}
	}
	return str;
}


//onBlur="javascript:checkme1(this);"
function checkme(quantity){ 
	if(quantity!="undefined"){
		if(quantity.value==""){
			alert("数据格式不正确，请输入一个大于等于0的整数！");
			return false;
		}
	}

	for(i=0;i< (quantity.value).length;i++){   
  	  var c = (quantity.value).charAt(i);
   	  if (!isDigit(c)) {
		alert("数据格式不正确，请输入一个大于等于0的整数！");
		quantity.value='0';
        quantity.focus();
		return false;
	  }
 	}
 	

	return true;
}

function isDigit (c)
{   
  return ((c >= "0") && (c <= "9")) ;
}

function checkmeNumber(dongxuelin){
   	  if (!(isIntegerChar(dongxuelin.value) && !isMoreThanOnce(dongxuelin.value,".") )) {
		alert("只接受数字和\".\"！");
		dongxuelin.value='0';
                dongxuelin.focus();
		return false;
	  }
	  if((dongxuelin.value).charAt(0) == "."){	  
		dongxuelin.value='0';
	  }
	return true;
}

function isMoreThanOnce(str,chr)
{
  return str.lastIndexOf(chr)!=str.indexOf(chr)
}

function isIntegerChar(s)
{
  for(i=0;i< s.length;i++)
  {   
    var c = s.charAt(i);
    if (c=="-" && i==0) 
    {
      continue; 
    }
    if (!isDigit(c) && c!=".") return false;
  }
  return true;
}
//用frame打开ModalDialog
function  openWindowModalDialogInFrame(theURL,iWidth,iHeight,scroll)
{
	 var vArguments=new Object();
	 vArguments.url=theURL;
	 vArguments.iWidth=iWidth;
	 vArguments.iHeight=iHeight;
	 vArguments.window=window;
	var iTop=(window.screen.height-iHeight)/2; 
	var iLeft=(window.screen.width-iWidth)/2; 
	if(scroll==null){
		scroll="no";
	}
	return window.showModalDialog("/nava/openWindowInfrmae.jsp",vArguments,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:"+scroll);
	
}


//用ModalDialog打开窗口
function  openWindowModalDialog(theURL,iWidth,iHeight,scroll)
{
	var iTop=(window.screen.height-iHeight)/2; 
	var iLeft=(window.screen.width-iWidth)/2; 
	if(scroll==null){
		scroll="no";
	}
	window.showModalDialog(theURL,window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:"+scroll);
	
}



//FCK内空检查check
function checkfckContent(contentname,content){
	var oEditor = FCKeditorAPI.GetInstance(content) ;				
		// Check the active editing mode.
		if ( oEditor.EditMode != FCK_EDITMODE_WYSIWYG )
		{
			alert("请选择为可编辑模式！");		
			return false;
		}
		
		
		var EditorDefaultvalue=oEditor.EditorDocument.body.innerHTML;//GetInnerHTML(content);
		var evalueLength=checkLength(EditorDefaultvalue);
		//alert(evalueLength);
		if(evalueLength==0||evalueLength==13){
			alert(contentname+"内容不能为空！");		
			return false;
		}
		//if(evalueLength>=3900)
		//{
		//	alert(contentname+"内容不能大于4000字符或者2000个汉字！");		
		///	return false;
		//}	
	return true;		
}

//FCK内空检查check
function checkfckContentReport(contentname,content){
	var oEditor = FCKeditorAPI.GetInstance(content) ;				
		// Check the active editing mode.
		if ( oEditor.EditMode != FCK_EDITMODE_WYSIWYG )
		{
			alert("请选择为可编辑模式！");		
			return false;
		}
		
		
		var EditorDefaultvalue=oEditor.EditorDocument.body.innerHTML;//GetInnerHTML(content);
		var evalueLength=checkLength(EditorDefaultvalue);
		//alert(evalueLength);
		if(evalueLength==0||evalueLength==13){
			alert(contentname+"内容不能为空！");		
			return false;
		}
		if(evalueLength>=3900)
		{
			alert(contentname+"内容不能大于4000字符或者2000个汉字！");		
			return false;
		}	
	return true;		
}
	
function GetInnerHTML(fckeditorname)
{
	var oEditor = FCKeditorAPI.GetInstance(fckeditorname);
	evalue=oEditor.EditorDocument.body.innerHTML;
	return evalue;
}
				
function InsertHTML(fckeditorname,hvalue)
{
	
	var oEditor = FCKeditorAPI.GetInstance(fckeditorname) ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml(hvalue) ;
	}
	else
	alert( 'You must be on WYSIWYG mode!' ) ;
}
				
function RemoveHTMLTags(str) {
  var len = str.length;
  var wrt = true;
  var ret = "";
  var chr;
  
  for (var c=0; c<len; c++) {
    chr = str.charAt(c); 
    switch (chr) {
      case '<':
        wrt = false;
        break;
      case '>':
        wrt = true;
        break;
      default:
        if (wrt) ret += chr;  
    }
  } // next
  
  return ret;
} 

//-----------------------------------------------------------------------------

//检验是否是数字
  function checkNumeric(strValue){
    var currencyPat=/^\d+$/;
    var matchArray=strValue.match(currencyPat);
    if (matchArray==null)
        return false;
    else 
        return true;
  }
  
function isDouble(strValue){
    var currencyPat=/^[-\+]?\d+(\.\d+)?$/;
    var matchArray=strValue.match(currencyPat);
    if (matchArray==null)
        return false;
    else 
        return true;
}

  
  //检查是否货币
  function checkCurrency(str) {
  
    var currencyPat=/^[-\+]?\d+(\.\d+)?$/;
    var matchArray=str.match(currencyPat);
    if (matchArray==null)
        return false;
    else 
        return true;
}
  
//检查邮件格式

function chkEmail(str) {
    var emailPat=/^$|\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    var matchArray=str.match(emailPat);
    if (matchArray==null)
        return false;
    else 
        return true;
}
//判断日期格式是否正确
function strDateTime(strDate){
    var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
    var arr = reg.exec(strDate);
    var year, month, day;

    if (strDate=="") return true;
    if (!reg.test(strDate)&&RegExp.$2<=12&&RegExp.$3<=31)
        return false;

    year = parseInt(strDate.split('-')[0], 10);
    month = parseInt(strDate.split('-')[1], 10);
    day = parseInt(strDate.split('-')[2], 10);

    if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
        return false;
    if ((month<=7) && ((month % 2)==0) && (day>=31))
        return false;
    if ((month>=8) && ((month % 2)==1) && (day>=31))
        return false;

    if (month==2) {
        if ((year%400==0) || ((year%4==0) && (year%100!=0))) {
            //闰年
            if (day>29)
                return false;
        }
        else if (day>28)
            //非闰年

            return false;
    }

    return true;
}
//去掉传入字符串中的空格

function trim(sp){
	var newsp;
	newsp=sp;
	loc=newsp.indexOf(" ");
	while (loc!=-1){
		newsp=newsp.replace(" ","");
		loc=newsp.indexOf(" ");
	}
	return newsp;
}

//取字符串的首字母

function firstLetter(sp){

	var newsp;
	newsp=sp;
	loc=newsp.substring(0,1);
	return loc;
}

//获得一组复选钮中的选中项

function getclickitems(groupname){
	var sel="";
	for(var i=0;i<groupname.length;i++){
		if (groupname[i].checked) {
			if(sel.length>0) sel = sel+",";
			sel = sel + groupname[i].value;
		}
	}
	return sel;
}

//计算字符串长度
function checkLength(strTemp){
		 var i,sum;
		 sum=0;
		 for(i=0;i<strTemp.length;i++)
		 {
		  if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
		   sum=sum+1;
		  else
		   sum=sum+2;
		 }
		 //alert(sum);
		 return sum;
	}
	
//判断号码是否为数字或字母	
function isLetterOrNum(theInt){

	theInt = theInt;
	for(var i=0;i<theInt.length;i++){
	    oneNum=theInt.substring(i,i+1);
        if (!((oneNum>="0"&&oneNum<="9")||(oneNum>="a"&&oneNum<="z")||(oneNum>="A"&&oneNum<="Z")))
          return false;
    }
	return true;
}
//电话号码检查
function CheckPhone(Phone) {
	 var ArryPhone = Phone.split("-")
    var Len = ArryPhone.length;
    //2"-"
    if (Len > 3)return false;
    //??
    for (var k =0;k <Len;k++) {
       if (ArryPhone[k].replace(/\d/gi,"") != "") return false;
    }
    //"-"?
    if ((Len > 1)&&(ArryPhone[0].length <1)) return false;  
    return true;
}
//过滤不安全字符和空格
function safestr(str)
{
	str=str.replace(/\'/g,"''");
	str=str.replace(/\ /g,"");
	return str;
}

// 去除EcSide自动获取的Post字段
function removeEcFlag(ecFlag, objName) {
	
	if("true" == ecFlag) {
		var objs = document.getElementsByName(objName);
		
		for (var i = (objs.length -1); i >=0; i --) {
		
			if ("hidden" == objs[i].getAttribute("type")) {
				objs[i].removeNode();
			}
		}
	}
}

function DateToStr(get_input_date) {
  var get_input_year = get_input_date.getYear();
  var get_input_month = get_input_date.getMonth() + 1;
  var get_input_day = get_input_date.getDate();

  if(get_input_year<1000) {
	get_input_year=1900 + get_input_year;
  }
  if(get_input_month<10) {
	get_input_month="0" + get_input_month;
  }
  if(get_input_day<10) {
	get_input_day="0" + get_input_day;
  }
  var dt = get_input_year + "-" + get_input_month + "-" + get_input_day;
  return dt;
}

//重组日期
function RebuildDate(val) {
	var date_array="";
	var get_input_date_str = val;
	var seperate;
	
	if(get_input_date_str == "") {
		return true;
	}
	
	if (get_input_date_str.indexOf("-") != -1) {
		seperate = "-";
	} else if (get_input_date_str.indexOf("/") != -1) {
		seperate = "/";
	} else if (get_input_date_str.indexOf(".") != -1) {
		seperate = ".";
	}
	
	date_array = get_input_date_str.split(seperate);
	
	if(date_array.length != 3) {
		return ""; 
	}
	if(date_array[0].length < 4) {
		return ""; 
	}
	
	date_array[1] = date_array[1] - 1;
	var get_input_date = new Date(date_array[0], date_array[1], date_array[2]);
	var dt = DateToStr(get_input_date);
	return dt;
 }

//比较两个日期大小
function CompareDate(date1, date2) {
	var dt1 = RebuildDate(date1);
	var dt2 = RebuildDate(date2);
	
	if ( dt1 > dt2 ) {
		return (1);
	} else if ( dt1 == dt2 ) {
		return (0); 
	} else {
		return (-1);
	}
}
//取消页面所有输入框禁用
function disableAllitems() {
    for (var i = 0; i < document.all.tags("INPUT").length; i++) {
        if (document.all.tags("INPUT")(i).type == "text") {
            document.all.tags("INPUT")(i).disabled = true;
        }
        if (document.all.tags("INPUT")(i).type == "checkbox") {
            document.all.tags("INPUT")(i).disabled = true;
        }
    }
    for (var i = 0; i < document.all.tags("SELECT").length; i++) {
        document.all.tags("SELECT")(i).disabled = true;
    }
    for (var i = 0; i < document.all.tags("TEXTAREA").length; i++) {
        document.all.tags("TEXTAREA")(i).disabled = true;
    }
    for (var i = 0; i < document.all.tags("A").length; i++) {
        document.all.tags("A")(i).href = "#";
    }
    document.getElementById("imgSearch").disabled = true;
}
function fckMobile(strMoney) {
    var reg = /^$|((\(\d{3}\))|(\d{3}\-))?13\d{9}|15[89]\d{8}$/;
    var arr = reg.exec(strMoney);
    if (strMoney == "") return false;
    return reg.test(strMoney);
}

//格式化金额#,###.00 (保留两位小数)
function formatNumber(num,pattern){
	if(num==""||num==null) return "0.00"
	num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);

}

//格式化金额#,###.00 (保留两位小数)
function formatEditNumber(num,pattern){
	num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+
    num.substring(num.length-(4*i+3));
    if(cents=="00")
    return (((sign)?'':'-') + num);
    else
    return (((sign)?'':'-') + num + '.' + cents);

}

//	function document.onmouseup()
//	{
//		if(ms!="")
//		{
//			event.srcElement.releaseCapture();
//			ms=0;
//		}
//	}
/// <summary>
/// 入力制御します（数字のみ入力可能）。
/// </summary>
/// <param name="argInputObj">入力のコントロール。</param>
/// <returns>
/// 正常の場合、nullを返す。
/// NGの場合、falseを返す。
/// </returns>
/// <remarks>2009/02/23 CIT祝暁燕</remarks>
function IsInteger(argString)
//更新 B票ID：1239 2008/04/14 END CITBJ 祝
{
    var regExp = /\D/;
    if(regExp.test(argString))
    {
        return false;
    }
    return true;
}

 function IsDate(date)
{
	var dates = date.split("/");
	var year = 0;
	var month = 0;
	var day = 0;
	var maxDay = 0;
	if (dates.length == 3) 
	{
		year = parseInt(dates[0],10);
		month = parseInt(dates[1],10);
		day = parseInt(dates[2],10);
		if (isNaN(year) || isNaN(month) || isNaN(month)) {
		    return false;
		}
		if (month < 1 || month > 12 || day < 1 || day > 31) {
			return false;
	    }
		maxDay = 30;
		if (month == 12 || month == 1 || month == 3
			|| month == 5 || month == 7 || month == 8 || month == 10) {
			maxDay = 31;
		} else if (month == 2) {
			if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
			{
				maxDay = 29;
			}
			else
			{
				maxDay = 28;
			}
		}
		if (day > maxDay)
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	return true;		
}

function IsIntegerGreater0(argString)
{
    var regExp = /^[0-9]*[1-9][0-9]*$/;
    if(regExp.test(argString))
    {
        return true;
    }
    return false;
}

function compareDate(first,second,sign)
{
    fArray = first.split(sign);
    sArray = second.split(sign);
    var fDate = new Date(fArray[0],fArray[1],fArray[2]);
    var sDate = new Date(sArray[0],sArray[1],sArray[2]);

    //var t = Math.abs(fDate.getTime()-sDate.getTime());
    var t = fDate.getTime()-sDate.getTime();
    var days = t/(1000*60*60*24);
    return days;
}